package demo_State;

import java.util.concurrent.TimeUnit;

//演示time_Waiting
public class State_Test2 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread =new Thread(()->{
            for (int i = 0; i <10 ; i++) {
                try {
                    //两种sleep方法
//                    Thread.sleep(1000);
                    TimeUnit.SECONDS.sleep(1);//单位是秒
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        //启动线程之前记录一下线程状态
        System.out.println("线程状态："+thread.getState()+" TCB是否存活："+thread.isAlive());
        //启动线程
        thread.start();
        //线程运行中记录线程状态
        Thread.sleep(1);//让打印线程慢一点防止抢占当前main线程抢占太快了
        System.out.println("线程状态："+thread.getState()+" TCB是否存活："+thread.isAlive());
        //等待线程运行结束,记录线程状态
        thread.join();
        System.out.println("线程状态："+thread.getState()+" TCB是否存活："+thread.isAlive());
    }
}
